# $Id$
# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>

_realname=indent
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.2.11
pkgrel=4
pkgdesc="C language source code formatting program (mingw-w64)"
arch=('any')
url="https://www.gnu.org/software/indent/"
license=('GPL3')
makedepends=('texinfo-tex')
source=(https://ftp.de.debian.org/debian/pool/main/i/indent/${_realname}_${pkgver}.orig.tar.gz
        indent-2.2.11-segfault.patch
        indent-2.2.11-LC_ALL.patch
        indent-2.2.11-decimal_format.patch
        indent-2.2.11-win32-wildexp-automake-support.patch
        indent-2.2.11-disable-documentation.patch)
sha256sums=('aaff60ce4d255efb985f0eb78cca4d1ad766c6e051666073050656b6753a0893'
            '63c66b49831a90c5191cd3295d17a4e1888d8fa2a0b02589448de3b78d4e0293'
            'ad8cc7670b99a7aad2a672f8f53c670da7a6de42e53bcc31ba88cbdea7db31bf'
            '84f089457b0c726645c8a02843b5f9df2b5ff60fd02c4c039027da4689e714c7'
            'cd55df7e1f6b5b0c8d2f037dcc0148c4e96a47cf939a74c6f69567d753e59777'
            '384d1edb3f99e53bed303fbbef9328c35ce4d48f9530a334721f849a096e8bd8')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  rm -rf regression/input/float-constant-suffix.c \
         regression/standard/float-constant-suffix.c > /dev/null 2>&1 || true

  patch -Np1 -i ../indent-2.2.11-segfault.patch

  # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=205692
  patch -Np1 -i ../indent-2.2.11-LC_ALL.patch

  # https://lists.gnu.org/archive/html/bug-indent/2011-08/msg00000.html
  patch -Np1 -i ../indent-2.2.11-decimal_format.patch

  patch -Np1 -i ../indent-2.2.11-win32-wildexp-automake-support.patch

  patch -Np1 -i ../indent-2.2.11-disable-documentation.patch

  # sed -i 's/-number/-number-sections/' doc/Makefile.in

  autoreconf -vfi
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --{host,build}=${MINGW_CHOST}

  make -j1
}

check() {
  cd "${srcdir}"/${_realname}-${pkgver}/regression
  make test
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR="${pkgdir}" install
  rm "${pkgdir}"${MINGW_PREFIX}/bin/texinfo2man.exe
}
